package com.itheima.demo1;

import java.text.BreakIterator;
import java.util.Scanner;

public class Practice6 {
    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);

        System.out.println("请输入存入金额! 1000起存!");

        //定义输入次数
        int i = 4;
        double money = sc.nextDouble();


        while (money < 1000) {
            System.out.println("金额错误!请重输!1000起存!共有5次输入机会.还剩" + i-- + "次");
            money = sc.nextDouble();
            if (i == 0) {
                System.out.println("输入错误,退出系统!");
                return;
            }
        }
        System.out.println("请输入存入年份!1年起存!最高4年!");

        int year = sc.nextInt();
        //判断年份是否输对.小于1年或者大于5年.不对的话.重新输入

        while (year < 1 || year > 5) {
            System.out.println("年份错误!1-4年,请重输!共有5次输入机会.还剩" + i-- + "次");
            year = sc.nextInt();
            if (i == 0) {
                System.out.println("输入错误,退出系统");
                return;
            }
        }

        double interest = 0;
        if (money >= 1000 && year == 1) {

            interest = money + money * 0.0225 * year;

            System.out.println("存1年的利息是:" + interest);


        } else if (money >= 1000 && year == 2) {

            interest = money + money * 0.027 * year;

            System.out.println("存2年的利息是:" + interest);
        } else if (money >= 1000 && year == 3) {

            interest = money + money * 0.0325 * year;

            System.out.println("存3年的利息是:" + interest);
        } else if (money >= 1000 && year == 4) {

            interest = money + money * 0.036 * year;

            System.out.println("存4年的利息是:" + interest);
        } else {
            System.out.println("请输入正确的年份跟金额!");
        }

    }

}
